<?php
include 'db_helper.php';

switch ($_REQUEST['method']) {
    case 'add_feed': addFeed(); break;
    default:
}

function addFeed() {
    $url = $_REQUEST['url'];
    $user_id = $_REQUEST['user_id'];

    $result = addFeedDB($url, $user_id);

    $response['state'] = array(
          'type' => 'state_response',
          'value' => $result
    );
    flushResponse($response);
}

function getFeeds() {
    $user_id = $_REQUEST['user_id'];

    $feeds = json_encode(getFeedsDB($user_id));

    $response['state'] = array(
          'type' => 'feed_response',
          'value' => $feeds
    );
    flushResponse($response);
}

function flushResponse($response) {
    $encodedResponse = json_encode($response);
    header('Content-type: application/json');
    exit($encodedResponse);
}
?>